package com.ctl.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ctl.dto.CategoryDTO;
import com.ctl.entity.Category;
import com.ctl.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/categories")
public class CategoryController {
    @Autowired
    private CategoryService service;

    @GetMapping("/{id}")
    public Map<String,Object> getName(@PathVariable Integer id){
        QueryWrapper<Category> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",id);
        Category category = service.getOne(queryWrapper);
        Map<String, Object> map = new HashMap<>();
        map.put("id",category.getId());
        map.put("name",category.getName());
        return map;
    }
    @GetMapping
    public List<CategoryDTO> getCategory(){
        return service.getCategoryAll();
    }

}
